From 20cf42c9ea977fe441c297a531811990876575c7 Mon Sep 17 00:00:00 2001 From: Carlos Soriano Date: Thu, 25 Feb 2016 14:25:40 +0100 Subject: [PATCH] gtkplacessidebar: avoid unresponsive UI while trashing We were updating the whole places sidebar when the trash changed. This effectively removes all rows and create new ones for every trash state change. Although when using GtkTreeView it was somehow ok, with the new implementation with GtkListBox this effectively locks the UI while the trash operations are being performed. When performing operations for i.e. 100 files, the UI can be locked for more than 1 minute since gvfs-trash usually takes time. To fix this just update the icon of the trash when the state of the trash change instead of the whole sidebar. https://bugzilla.gnome.org/show_bug.cgi?id=762677 --- gtk/gtkplacessidebar.c | 21 +++++++++++++++------ gtk/gtksidebarrow.c | 27 +++++++++++++++++++++------ gtk/gtksidebarrowprivate.h | 2 ++ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c index 3de9e2cd66..ba8d3c0241 100644 --- a/gtk/gtkplacessidebar.c +++ b/gtk/gtkplacessidebar.c @@ -132,6 +132,7 @@ struct _GtkPlacesSidebar { gchar *rename_uri; gulong trash_monitor_changed_id; + GtkWidget *trash_row; /* DND */ GList *drag_list; /* list of GFile */ @@ -878,6 +879,14 @@ is_external_volume (GVolume *volume) return is_external; } +static void +update_trash_icon (GtkPlacesSidebar *sidebar) +{ + if (sidebar->trash_row) + gtk_sidebar_row_set_icon (GTK_SIDEBAR_ROW (sidebar->trash_row), + _gtk_trash_monitor_get_icon (sidebar->trash_monitor)); +} + static void update_places (GtkPlacesSidebar *sidebar) { @@ -980,11 +989,11 @@ update_places (GtkPlacesSidebar *sidebar) { mount_uri = "trash:///"; /* No need to strdup */ icon = _gtk_trash_monitor_get_icon (sidebar->trash_monitor); - add_place (sidebar, PLACES_BUILT_IN, - SECTION_COMPUTER, - _("Trash"), icon, mount_uri, - NULL, NULL, NULL, 0, - _("Open the trash")); + sidebar->trash_row = add_place (sidebar, PLACES_BUILT_IN, + SECTION_COMPUTER, + _("Trash"), icon, mount_uri, + NULL, NULL, NULL, 0, + _("Open the trash")); g_object_unref (icon); } @@ -3773,7 +3782,7 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar) sidebar->trash_monitor = _gtk_trash_monitor_get (); sidebar->trash_monitor_changed_id = g_signal_connect_swapped (sidebar->trash_monitor, "trash-state-changed", - G_CALLBACK (update_places), sidebar); + G_CALLBACK (update_trash_icon), sidebar); gtk_widget_set_size_request (GTK_WIDGET (sidebar), 140, 280); diff --git a/gtk/gtksidebarrow.c b/gtk/gtksidebarrow.c index a095bd2655..3df5b026dd 100644 --- a/gtk/gtksidebarrow.c +++ b/gtk/gtksidebarrow.c @@ -156,11 +156,7 @@ gtk_sidebar_row_set_property (GObject *object, break; case PROP_ICON: - g_set_object (&self->icon, g_value_get_object (value)); - if (self->icon != NULL) - gtk_image_set_from_gicon (GTK_IMAGE (self->icon_widget), self->icon, GTK_ICON_SIZE_MENU); - else - gtk_image_clear (GTK_IMAGE (self->icon_widget)); + gtk_sidebar_row_set_icon (self, g_value_get_object (value)); break; case PROP_LABEL: @@ -239,7 +235,7 @@ gtk_sidebar_row_set_property (GObject *object, (GtkCallback) gtk_widget_destroy, NULL); - context = gtk_widget_get_style_context (GTK_WIDGET (self)); + context = gtk_widget_get_style_context (GTK_WIDGET (self)); gtk_style_context_add_class (context, "sidebar-placeholder-row"); } break; @@ -283,6 +279,25 @@ gtk_sidebar_row_hide (GtkSidebarRow *self, gtk_revealer_set_transition_duration (GTK_REVEALER (self->revealer), transition_duration); } +void +gtk_sidebar_row_set_icon (GtkSidebarRow *self, + GIcon *icon) +{ + g_return_if_fail (GTK_IS_SIDEBAR_ROW (self)); + + if (self->icon != icon) + { + g_set_object (&self->icon, icon); + if (self->icon != NULL) + gtk_image_set_from_gicon (GTK_IMAGE (self->icon_widget), self->icon, + GTK_ICON_SIZE_MENU); + else + gtk_image_clear (GTK_IMAGE (self->icon_widget)); + + g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ICON]); + } +} + static void gtk_sidebar_row_finalize (GObject *object) { diff --git a/gtk/gtksidebarrowprivate.h b/gtk/gtksidebarrowprivate.h index 8042757c99..d13dc6d830 100644 --- a/gtk/gtksidebarrowprivate.h +++ b/gtk/gtksidebarrowprivate.h @@ -50,6 +50,8 @@ void gtk_sidebar_row_reveal (GtkSidebarRow *self); GtkWidget *gtk_sidebar_row_get_eject_button (GtkSidebarRow *self); GtkWidget *gtk_sidebar_row_get_event_box (GtkSidebarRow *self); +void gtk_sidebar_row_set_icon (GtkSidebarRow *self, + GIcon *icon); G_END_DECLS -- 2.30.2